package com.party.mobile.web.controller.photo;

import com.party.common.paging.Page;
import com.party.core.exception.BusinessException;
import com.party.core.model.photo.PhotosMemberOperate;
import com.party.core.model.photo.PhotosRankOutput;
import com.party.mobile.biz.photo.RankBizService;
import com.party.mobile.web.dto.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 排行
 * @Author: yangshoukun
 * @Date: 2018/6/5 9:58
 */
@Controller
@RequestMapping(value = "/photos/rank")
public class RankController {

    @Autowired
    private RankBizService rankBizService;

    /**
     * 排名列表
     * @param operate
     * @param page
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public AjaxResult list(PhotosMemberOperate operate, Page page) {
        try {
            List<PhotosRankOutput> list = rankBizService.list(operate, page);
            return AjaxResult.success(list, page);
        } catch (BusinessException be) {
            return AjaxResult.error(AjaxResult.ERROR_CODE, be.getMessage());
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }

    /**
     * 获取自己排名
     * @param operate
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/self")
    public AjaxResult self(PhotosMemberOperate operate) {
        try {
            PhotosRankOutput output = rankBizService.self(operate);
            return AjaxResult.success(output);
        } catch (BusinessException be) {
            return AjaxResult.error(AjaxResult.ERROR_CODE, be.getMessage());
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }
}
